package com.yuan.dingtalk.service;

import com.taobao.api.ApiException;
import com.yuan.dingtalk.service.cache.DingtalkCacheFactory;
import com.yuan.dingtalk.service.cache.IDingtalkCache;

/**
 * 缓存实现类，此类用来处理dingtalk access_token
 */
public abstract class AbstractCacheDingtalk extends AbstractDingtalkService {

    private static IDingtalkCache dingtalkChace;
    /**
     * 默认缓存方式内存缓存
     */
    private String cacheType = "memory";

    public AbstractCacheDingtalk(String apiUrl, String cacheType) {
        super(apiUrl);
        dingtalkChace = DingtalkCacheFactory.instance(this).getDingtalkCache(cacheType);
    }

    @Override
    public String getCacheAccessToken(String appKey, String appSecret) throws ApiException {
        String accessToken = dingtalkChace.getAccessToken(appKey, appSecret);
        return accessToken;
    }
}
